/* Millennium Falcon with Pure CSS */
let aaa= function() {
  

    var canvas = document.querySelector("canvas");
    var scale = window.devicePixelRatio;
    var wHeight = window.innerHeight;
    var wWidth = window.innerWidth;
    console.log(wWidth, window)
    var wHeight = window.innerHeight;
    console.log(canvas)

    canvas.width = wWidth;
    canvas.height = wHeight;
    console.log("------------", canvas.width, canvas.height)
    var ctx = canvas.getContext("2d");

    // const b=document.body.clientHeight;
    // const c=window.screen.height;
    // console.log("可见"+a);
    // canvas.width = b;
    // canvas.height = a;

    let MAX_STARS = 2000;
    const STAR_COLORS = ["#444", "#888", "#FFF"];

    class Stars {
      constructor() {
        this.stars = [];
        for (let i = 0; i < MAX_STARS; i++) {
          const x = ~~(Math.random() * canvas.width);
          const y = ~~(Math.random() * canvas.height);
          const speed = ~~(1 + Math.random() * 3);
          const color = ~~(Math.random() * 3);
          this.stars.push({ x, y, speed, color });

        }
      }

      draw() {
        for (let i = 0; i < MAX_STARS; i++) {
          const star = this.stars[i];
          ctx.lineWidth = 1;
          ctx.strokeStyle = STAR_COLORS[this.stars[i].color];
          ctx.strokeRect(star.x, star.y, 1, 1);
          // console.log(ctx.strokeStyle)
        }
      }

      update() {
        for (let i = 0; i < MAX_STARS; i++) {
          this.stars[i].y += this.stars[i].speed;
          const isOutScreen = this.stars[i].y > canvas.height;
          isOutScreen && (this.stars[i].y = 0);
          // console.log("eee")
        }
      }
    }
   


    // console.log(stars.stars);

    const clearScreen = () => ctx.clearRect(0, 0, canvas.width, canvas.height);
    let stars = new Stars();
    let loop= function () {

      clearScreen();
      requestAnimationFrame(loop);
      stars.update();
      stars.draw();
    };
    loop()

  

window.addEventListener("resize", function () {
  scale = window.devicePixelRatio;
  wHeight = window.innerHeight;
  wWidth = window.innerWidth;
  var c = document.querySelector("canvas");
  console.log(c)
  console.log("窗口大小在变化");
  wHeight = window.innerHeight;
  wWidth = window.innerWidth;
  c.width = wWidth;
  c.height = wHeight;
  console.log("kuang " + c.width)
  console.log("gao  " + c.height)
  // loop();
  MAX_STARS = innerWidth * 1.2
  stars = new Stars();
});
}
module.exports = aaa;
